<h2 class="dialog_title"><span>Daftar Prestasi / Pelanggaran</span></h2>
<div class="dialog_content" style="padding: 10px 20px; width:700px">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
	<tr>
		<td width="80">Bidang : </td>
        <td><strong><?php echo $achievBidang?></strong></td>
	</tr>
	<tr>
    	<td>Periode : </td>
		<td><strong><?php echo date('m-Y', $startPeriode) ?> - <?php echo date('m-Y', $endPeriode) ?></strong></td>
	</tr>
</table>
<table style="border:1px solid #457A3F;" width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr class="header">
	<th align="left"><span class="colorWhite">Kode Karyawan</span></th>
    <th align="left"><span class="colorWhite">Nama Karyawan</span></th>
    <th align="left"><span class="colorWhite">Periode</span></th>
    <th align="left"><span class="colorWhite">Jenis</span></th>
    <th align="left"><span class="colorWhite">Tingkat</span></th>
    <th align="left"><span class="colorWhite">Kategori</span></th>
    <th align="right"><span class="colorWhite">Jumlah</span></th>
  </tr>
  <tbody id="searchKary-table" style="overflow:scroll; height:200px" >
<?php 
	$sql2 = "SELECT h.NAMA_DEPARTMENT, a.KODE_KARYAWAN, e.NAMA_KARYAWAN, DATE_FORMAT(a.PERB_TGL,'%m-%Y') AS PERB_TGL,
					c.ACHIEV_JENIS, d.DETACHIEV_TINGKAT, d.DETACHIEV_NAMA, COUNT(b.DETACHIEV_ID) AS COUNT
			FROM perbuatan AS a, detil_perbuatan AS b, prestasipelanggaran AS c, detil_prestasi_pelanggaran AS d, 
				data_karyawan as e, relasi_div_jab_din as f, dep_divisi_jabatan as g, data_department as h
			WHERE a.PERB_NO = b.PERB_NO
				AND b.DETACHIEV_ID = d.DETACHIEV_ID
				AND d.ACHIEV_ID = c.ACHIEV_ID
				AND a.KODE_KARYAWAN = e.KODE_KARYAWAN
				AND e.KODE_KARYAWAN  = f.KODE_KARYAWAN 
				AND f.ID_DEP_DIV_JAB = g.ID_DEP_DIV_JAB 
				AND	g.ID_DEPARTMENT  = h.ID_DEPARTMENT
				AND DATE_FORMAT( a.PERB_TGL, '%Y-%m' ) 
					BETWEEN DATE_FORMAT('". date('Y-m-d', $startPeriode) ."', '%Y-%m' ) AND 
							DATE_FORMAT('". date('Y-m-d', $endPeriode) ."', '%Y-%m') 
				AND c.ACHIEV_BIDANG = '$achievBidang'
			GROUP BY h.ID_DEPARTMENT, a.KODE_KARYAWAN, PERB_TGL 
			ORDER BY h.ID_DEPARTMENT, a.KODE_KARYAWAN, PERB_TGL";
//	AND c.ACHIEV_JENIS = '$jenis'

	//1. hitung jumlah seluruhnya
	$countAll = 0;

	//2. the data
	$result = mysql_query($sql2);  
?>
<?php while ($row = mysql_fetch_assoc($result)):?>
	<?php $countAll+=$row['COUNT']?>
	<?php if (strtolower($row['ACHIEV_JENIS'])!=$jenis) continue;?>
	<?php if ($lastName=="" || $lastName != $row['NAMA_DEPARTMENT']) : ?>
    <?php $nameCount++; ?>
    <?php $lastName=$row['NAMA_DEPARTMENT'] ?>
    <tr bgcolor="#CCCCCC">
        <td colspan="7"><?php echo $row['NAMA_DEPARTMENT'] ?></td>
    </tr>
    <?php endif;?>
    
  <tr <?php echo tag_zebra($z++)?>>
  	<td><?php echo $row['KODE_KARYAWAN']?></td>
    <td><?php echo $row['NAMA_KARYAWAN']?></td>
    <td><?php echo $row['PERB_TGL']?></td>
    <td><?php echo $row['ACHIEV_JENIS']?></td>
    <td><?php echo $row['DETACHIEV_TINGKAT']?></td>
    <td><?php echo $row['DETACHIEV_NAMA']?></td>
    <td align="right"><?php echo $row['COUNT']?></td>
  </tr>
  <?php $count+=$row['COUNT'] ?>
<?php endwhile;?>
  </tbody>
  <tr class="header">
	<th align="right" colspan="6"><span class="colorWhite">Jumlah <?php echo ucfirst($jenis)?> : </span></th>
    <th align="right"><span class="colorWhite"><?php echo $count?></span></th>
  </tr>
  <tr class="header">
  	<th align="right" colspan="6"><span class="colorWhite">Jumlah Prestasi dan Pelanggaran : </span></th>
    <th align="right"><span class="colorWhite"><?php echo $countAll?></span></th>
  </tr>
  <tr class="header">
  	<th align="right" colspan="6"><span class="colorWhite">Total : </span></th>
    <th align="right"><span class="colorWhite"><?php echo number_format($count/$countAll,2)?></span></th>
  </tr>
</table>
</div>
<div class="dialog_buttons"><input type="button" value="Close" name="close" onclick="FBModal_hide()" /></div>